<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>并集</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box {
            display: grid;
            grid-row-gap: 10px;
            grid-template-columns: 80px 20px;
        }

        h3 {
            padding-bottom: 10px;
            border-bottom: 2px solid #9d9a9a;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <h3>控制显隐</h3>
        <div class="box">
            <label for="">原始多边形</label><input type="checkbox" onchange="showPolygon()">
            <label for="">交集多边形</label><input type="checkbox" checked="true" onchange="showpolygonUnion()">
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']
        const objm = new ESObjectsManager();
        window.g_objm = objm;


        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            "domid": document.getElementById("app")
        })
        // 监听视口状态
        viewer.statusChanged.don(status => {
            if (status == 'Created') {
                // 视口创建完成，飞到初始视角位置
                objm.activeViewer.flyIn([
                    107.89993754592979,
                    25.98072878339561,
                    1259.9441451178973
                ], [
                    277.1313699341964,
                    -38.01618948781485,
                    0.0007118972316128277
                ], 3)
            }
        })
        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        // Vue中引入方式：import { ESGeoPolygon } from 'xbsj-xe2/dist-node/xe2';
        const { ESGeoPolygon } = XE2['esobjs-xe2-plugin-main']
        // 创建多边形1
        const polygon1 = objm.createSceneObject(ESGeoPolygon)

        // show控制显隐
        polygon1.show = false

        // 顶点数组(经度、纬度、高度)
        polygon1.points = [
            [
                107.8830830124989,
                25.9831926536704,
                -1.1406325468715177e-9
            ], [
                107.88286962897807,
                25.97976724221076,
                0
            ], [
                107.8876444691448,
                25.97995955715413,
                0
            ], [
                107.88564081868817,
                25.984112267253536,
                0
            ]
        ]


        // 创建多边形2
        const polygon2 = objm.createSceneObject(ESGeoPolygon)

        // show控制显隐
        polygon2.show = false
        // 顶点数组(经度、纬度、高度)
        polygon2.points = [
            [
                107.88427166510375,
                25.98661778284964,
                0
            ],
            [
                107.8817454525063,
                25.983091660121524,
                0
            ],
            [
                107.88494695327158,
                25.981508689515504,
                -0.3961426173584137
            ],
            [
                107.88800427452989,
                25.985012809628646,
                0
            ],
            [
                107.88800427452989,
                25.985012809628646,
                0
            ]
        ]

        // getUnion获取交集，返回【多个】【多边形数组信息】
        const result = polygon1.getUnion(polygon2.points)// 求交的结果（多个多边形数组）
        // 创建交集多边形，并设置不同样式
        const polygonUnion = objm.createSceneObject(ESGeoPolygon)
        // 开启面样式
        polygonUnion.filled = true
        // 设置面样式为纯蓝色
        polygonUnion.fillStyle = {
            "color": [
                0,
                0,
                1,
                1
            ],
            "material": "",
            "materialParams": {},
            "ground": false//是否贴地
        }
        // 设置点位信息
        polygonUnion.points = result[0]

        // 显示或隐藏交集多边形
        function showpolygonUnion() {
            polygonUnion.show = !polygonUnion.show
        }

        // 显示或隐藏两个原始多边形
        function showPolygon() {
            polygon1.show = !polygon1.show
            polygon2.show = !polygon2.show
        }




    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>